Ext.ux.HTMLEditorEditImage = function(config){

  var editor;  
  
  this.init = function(htmlEditor) {
    editor = htmlEditor;
    //editor.on('render', onRender, this);
    editor.range = null;
  	
  	editor.tb.insertToolsBefore('createlink', {
      itemId: 'insertimage',
      cls : 'x-btn-icon x-edit-insertimage',
      handler: onEditImage,
      scope: this,
      clickEvent: 'click',
      tooltip: {
				cls: 'none',
				title: 'Image',
				text: 'Open insert image dialog.'
			}
    });    
    
  }

  
  
	function onEditImage() {
		
		if(Ext.isIE){
    	if (editor.doc.selection.type == 'Control') {
  			editor.con = editor.doc.selection;
  			editor.range = null;
  			alert("Выберите текст, а не объект");
  			return
    	} else if (editor.doc.selection.type == 'Text') {
  			editor.con = null;
  			editor.range = editor.doc.selection.createRange();
  			editor.html = editor.range.htmlText;
    	} else {
  			editor.con = null;
  			editor.range = editor.doc.selection.createRange();
    	}
    }
    
    
    var selObj = editor.win.getSelection()
		alert(selObj);

    return
    
	  var fs = new Ext.form.FormPanel({
	  		frame: false,
	      labelAlign: 'right',
	      id: 'edit_image_form_panel',
	      labelWidth: 85,
	      waitMsgTarget: true,
	      cls: 'form_container',
				//border: false,
				items: [{
					xtype:'textfield',
					fieldLabel: 'Title',
					name: 'title',
					width:'50%'
				}]
	  });

    
    var editImageWindow = new Ext.Window({ 
      title: "Paste text from Microsoft Word",  
      modal: true,
      border: false,
			draggable: false,
			shadow: false,
			width:460,
			height:230,
			closeAction:'close',
			bodyStyle:'padding: 5 8 0 8',
      resizable: false,
      plain: true,
      items: fs,
      buttons: [{
        text: 'Ok',
        handler: function() {
          var i_title = fs.getForm().findField("title").getValue();
          editor.focus();
		      if (Ext.isIE) {
		      	editor.range.pasteHTML('<img src="/img/page.gif"/ title="'+ i_title +'"/>');
		      } else {
		        editor.execCmd('InsertHTML', '<img src="/img/page.gif"/ title="'+ i_title +'"/>');
		      }
          editImageWindow.close();
        },
        scope: this
      }, {
        text: 'Cancel',
        handler: function() {
          editImageWindow.close();
        }
      }]
    });
    
    editImageWindow.show();
  };
    
};
